//
// Created by Administrator on 2020/7/4.
//实验四(下):
//1.学习类的组合使用方法;
//2.观察构造函数和析构函数的执行过程。
//例2:声明一个CPU类、RAM类、CDROM类的基础上,再声明Computer类。
//    要求：其中声明私有数据成员cpu、ram、cdrom,声明公有成员函数run、stop,可在其中输出提示信息。
//    2.在main()函数中声明一个Computer类的对象,调用其成员函数。


#include <iostream>
using namespace std;
//CPU类
enum CPU_Rank{P1=1,P2,P3,P4,P5,P6,P7};
class CPU
{
private://私有成员
    CPU_Rank rank;
    int frequency;
    float voltage;
public://公有成员
    CPU(CPU_Rank r,int f,float v)//构造函数(分别对应私有数据成员)
    {
        rank=r;
        frequency=f;
        voltage=v;
        cout<<"您构造了一个CPU!"<<endl;
    }
    ~CPU(){cout<<"您析构了一个CPU!"<<endl;}//析构函数
    //以下外部访问接口函数
    CPU_Rank GetRank() const {return rank;}
    int GetFrequency() const {return frequency;}
    float GetVoltage() const {return voltage;}

    void SetRank(CPU_Rank r){rank=r;}
    void SetFrequency(int f){frequency=f;}
    void SetVoltage(float v){voltage=v;}
    //以下为成员函数
    void Run(){cout<<"CPU开始运行!"<<endl;}
    void Stop(){cout<<"CPU停止运行"<<endl;}
};
//RAM类
enum RAM_Type{DDR2=2,DDR3,DDR4};
class RAM
{
private:
    enum RAM_Type type;
    unsigned int frequency;//MHz
    unsigned int size;//GB
public:
    RAM(RAM_Type t,unsigned int f,unsigned int s)
    {
        type=t;
        frequency=f;
        size=s;
        cout<<"您构造了一个RAM!"<<endl;
    }
    ~RAM(){cout<<"您析构了一个RAM"<<endl;}

    RAM_Type GetType(){return type;}
    unsigned int GetFrequency(){return frequency;}
    unsigned int GetSize(){return size;}

    void SetType(RAM_Type t){type=t;}
    void SetFrequency(unsigned int f){frequency=f;}
    void SetSize(unsigned int s){size=s;}

    void Run(){cout<<"RAM开始运行!"<<endl;}
    void Stop(){cout<<"RAM停止运行"<<endl;}

};
//CD_ROM类
enum CDROM_Interface{SAta,USB};
enum CDROM_Install_type{external,built_in};
class CD_ROM
{
private:
    enum CDROM_Interface interface_type;
    unsigned int cache_size;//MB
    CDROM_Install_type install_type;
public:
    CD_ROM(CDROM_Interface i,unsigned int s,CDROM_Install_type it)
    {
        interface_type=i;
        cache_size=s;
        install_type=it;
        cout<<"您构造了一个CD_ROM!"<<endl;
    }
    ~CD_ROM(){cout<<"您析构了一个CD_ROM"<<endl;}

    CDROM_Interface GetInterfaceType() const{return interface_type;}
    unsigned int GetSize()const{return cache_size;}
    CDROM_Install_type GetInstallType()const{return install_type;}

    void SetInterfaceType(CDROM_Interface i){interface_type=i;}
    void SetSize(unsigned int s){cache_size=s;}
    void SetInstallType(CDROM_Install_type it){install_type=it;}

    void Run(){cout<<"CD_ROM开始运行!"<<endl;}
    void Stop(){cout<<"CD_ROM停止运行"<<endl;}
};
//Computer类
class Computer
{
private:
    CPU my_cpu;
    RAM my_ram;
    CD_ROM my_cdRom;
    unsigned int storage_size;//GB
    unsigned int bandwidth;//MB
public:
    Computer(CPU c,RAM r,CD_ROM cd,unsigned int s,unsigned int b);

    ~Computer(){cout<<"析构了一个Computer!"<<endl;}

    void Run()
    {
        my_cpu.Run();
        my_ram.Run();
        my_cdRom.Run();
        cout<<"Computer开始运行！"<<endl;
    }

    void Stop()
    {
        my_cpu.Stop();
        my_ram.Stop();
        my_cdRom.Stop();
        cout<<"Computer停止运行！"<<endl;
    }
};

Computer::Computer(CPU c, RAM r, CD_ROM cd, unsigned int s, unsigned int b):my_cpu(c),my_ram(r),my_cdRom(cd)
{
    storage_size=s;
    bandwidth=b;

    cout<<"您构造了一个computer！"<<endl;
}
//主函数
int main()
{
    CPU a(P6,300,2.8);
    a.Run();
    a.Stop();
    cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";

    RAM b(DDR3,100,8);
    b.Run();
    b.Stop();
    cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";

    CD_ROM c(SAta,2,built_in);
    c.Run();
    c.Stop();
    cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";

    Computer my_computer(a,b,c,128,10);
    my_computer.Run();
    my_computer.Stop();
    cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";

    return 0;
}